package upm.pb4agent.team5;

import es.decoroso.communicationAgent.CommunicationAgent;
import jade.domain.FIPAException;
import jade.wrapper.StaleProxyException;
import upm.pb4agent.team5.common.Referee;
import upm.pb4agent.team5.common.RegistrationDesk;

public class AgPlatform5 extends BaseAgent {
	private static final long serialVersionUID = -952632286051634074L;
	public final static String DF_NAME = "AgPlatform5";
	
    public AgPlatform5() {
		super(DF_NAME);
	}
    
	/**
     * Method executed when agent is initialized
     */
	protected void setup() {
		System.out.println(getLocalName() + ": Enters the system");

		try {
			startCommunicationAgent();
			startReferee();
			startRegistrationDesk();

		} catch (StaleProxyException e) {
			System.err.println(getLocalName() + ": Agent creation failed");
		} catch (InterruptedException e) {
			System.err.println(getLocalName() + ": Thread.sleep failed");
		} catch (FIPAException e) {
			System.err.println(getLocalName() + ": DF search failed");
		}

		doDelete();
	}

	private void startRegistrationDesk() throws StaleProxyException, InterruptedException, FIPAException {
		createAgent(RegistrationDesk.class, RegistrationDesk.DF_NAME, null, false);
	}
	
	private void startReferee() throws StaleProxyException, InterruptedException, FIPAException {
		createAgent(Referee.class, Referee.DF_NAME, null, false);		
	}

	private void startCommunicationAgent() throws StaleProxyException, InterruptedException, FIPAException {
		createAgent(CommunicationAgent.class, "CommunicationAgent", null, false);		
	}
}
